package team.seekers.hula.course.resource.sectionContent.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.BaseDO;
import team.seekers.hula.course.resource.sectionContent.entity.dto.SectionContentDTO;
import team.seekers.hula.course.resource.sectionContent.entity.dto.SectionContentListDTO;
import team.seekers.hula.course.resource.sectionContent.entity.dto.SectionContentManageDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(SectionContentDOField.TABLE_NAME)
public class SectionContentDO extends BaseDO {

    private static final long serialVersionUID = 1L;

    @TableId(value = SectionContentDOField.ID, type = IdType.ASSIGN_ID)
    private String id;
    /**
     * 课程id
     */
    @TableField(SectionContentDOField.COURSE_ID)
    private String courseId;
    /**
     * 章id
     */
    @TableField(SectionContentDOField.CHAPTER_ID)
    private String chapterId;
    /**
    /**
     * 章节id
     */
    @TableField(SectionContentDOField.SECTION_ID)
    private String sectionId;
    /**
     * 创建者id
     */
    @TableField(SectionContentDOField.USER_ID)
    private String userId;
    /**
     * 如果是视频则用pieces存储分段方案
     */
    @TableField(SectionContentDOField.PIECES)
    private String pieces;
    /**
     * 内容名称
     */
    @TableField(SectionContentDOField.NAME)
    private String name;
    /**
     * 内容名称
     */
    @TableField(SectionContentDOField.CONTENT)
    private String content;
    /**
     * 类型（0 富文本、1 视频、2 题目）
     */
    @TableField(SectionContentDOField.TYPE)
    private Integer type;

    @TableField(SectionContentDOField.SEQUENCE)
    private Integer sequence;

    /**
     * 版本号
     */
    @TableField(SectionContentDOField.VERSION)
    private Integer version;

    /**
     * 版本名称
     */
    @TableField(SectionContentDOField.VERSION_DESCRIPTION)
    private String versionDescription;

    /**
     * 是否可见，配合版本号进行回滚操作
     */
    @TableField(SectionContentDOField.IS_VISIBLE)
    private Integer isVisible;

    @TableField(SectionContentDOField.DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(value = SectionContentDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = SectionContentDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    public static SectionContentDO fromDTO(SectionContentDTO contentDTO) {
        SectionContentDO sectionContentDO = new SectionContentDO();
        BeanUtils.copyProperties(contentDTO,sectionContentDO);
        return sectionContentDO;
    }

    public static List<SectionContentListDTO> toVOList(List<SectionContentDO> contentDOList) {
        ArrayList<SectionContentListDTO> sectionContentListDTOS = new ArrayList<>();
        for (SectionContentDO sectionContentDO : contentDOList) {
            SectionContentListDTO sectionContentListDTO = new SectionContentListDTO();
            BeanUtils.copyProperties(sectionContentDO,sectionContentListDTO);
            sectionContentListDTOS.add(sectionContentListDTO);
        }
        return sectionContentListDTOS;
    }
    public static List<SectionContentDTO> toDTOList(List<SectionContentDO> contentDOList) {
        ArrayList<SectionContentDTO> sectionContentDTOS = new ArrayList<>();
        for (SectionContentDO sectionContentDO : contentDOList) {
            SectionContentDTO sectionContentDTO = new SectionContentDTO();
            BeanUtils.copyProperties(sectionContentDO,sectionContentDTO);
            sectionContentDTOS.add(sectionContentDTO);
        }
        return sectionContentDTOS;
    }

    public static SectionContentDTO toDTO(SectionContentDO sectionContentDO) {
        SectionContentDTO sectionContentDTO = new SectionContentDTO();
        BeanUtils.copyProperties(sectionContentDO,sectionContentDTO);
        return sectionContentDTO;
    }
}
